<?php
/**
 * Created by PhpStorm.
 * User: sunku
 * Date: 2018/2/28
 * Time: 17:49
 */

namespace Resource\Model;
use Think\Model;


class UploadModel extends Model
{
    protected $trueTableName = 'wz_upload';
    /**
     * 添加
     * @param $params
     * @return mixed
     */
    public function addUpload($params) {
        $params['create_time'] = time();
        return $this->add($params);
    }

    /**
     * 查询信息
     * @param $params
     * @param string $fields
     * @return mixed|Model
     */
    public function getUploadInfo($params, $fields = '') {
        if($fields) {
            $dataInfo = $this->where($params)->field($fields)->find();
        } else {
            $dataInfo = $this->where($params)->find();
        }

        return $dataInfo;
    }

    /**
     * @param $params
     * @return mixed
     */
    public function getUploadCount($params) {
        return $this->where($params)->count();
    }

    /**
     * 查询列表
     * @param $params
     * @param int $page
     * @param int $page_size
     * @return array
     */
    public function getUploadList($params, $page=1, $page_size=20) {
        $dataList = $this->where($params)->order('create_time DESC')->limit($page_size)->page($page)->select();
        return $dataList ? $dataList : [];
    }

    /**
     * 更新item信息
     * @param $params
     * @return bool
     */
    public function updateUploadInfo($params) {
        $params['update_time'] = time();
        $result = $this->save($params);
        if($result !== false) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @param $params
     * @return array
     */
    public function getAllUploadList($params) {
        $dataList = $this->where($params)->order('create_time DESC')->select();
        return $dataList ? $dataList : [];
    }

    /**
     * 删除
     * @param $params
     * @return bool
     */
    public function deleteUpload($params) {
        $result = $this->where($params)->delete();
        if($result !== false) {
            return true;
        } else {
            return false;
        }
    }
}